package com.codingman.thymeleafdemo1;

import java.io.IOException;
import java.util.Calendar;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.WebContext;

public class demo2Servlet extends HttpServlet {
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		Employee emp = new Employee(101, "Ann", 100.00);
		
		HttpSession session = request.getSession();
		session.setAttribute("user", "Bob");
		
		WebContext ctx = new WebContext(request, response, request.getServletContext());
		ctx.setVariable("employee", emp);
		ctx.setVariable("today", Calendar.getInstance());
		
		TemplateEngine engine = ThymeleafUtil.getTemplateEngine(request.getServletContext());
		engine.process("demo2", ctx, response.getWriter());
	}
}
